﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtAspNet;

namespace HY.WEB.SA
{
    public partial class sch_edit_all : PageBase
    {

        string sid = "";
        public string us,um;
        string tab = "school";
        public BLL.SC.schools jbs = new BLL.SC.schools();

        protected void Page_Load(object sender, EventArgs e)
        {
            us = Session["ID"].ToString();
            um = Session["user"].ToString();
            if (!IsPostBack)
            {
                if (!string.IsNullOrEmpty(Request["sid"]))
                {
                    sid = Request["sid"].Trim();

                    hidsid.Text = sid;
                    BindText(sid);
                }
                fill(); 
            }

        }

        void fill()
        {

            //客户性质
            DataTable e = BLL.Bllbase.get_table("[sch_type]");
            ddltype.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddltype.Items.Add(new ExtAspNet.ListItem(e.Rows[i][2].ToString(), e.Rows[i][2].ToString()));
            }
            ddltype.DataBind();
            ddltype.Items.Add(new ExtAspNet.ListItem("", ""));

           

            //客户性质
            e = BLL.Bllbase.get_table("[sch_xz]");
            ddlxz.Items.Clear();
            for (int i = 0; i < e.Rows.Count; i++)
            {
                ddlxz.Items.Add(new ExtAspNet.ListItem(e.Rows[i][2].ToString(), e.Rows[i][2].ToString()));
            }
            ddlxz.DataBind();
            ddlxz.Items.Add(new ExtAspNet.ListItem("", ""));

  

        }

     
        void BindText(string sid)
        {
            DataTable dt = jbs.GetList("sid=" + sid).Tables[0];

            if (dt.Rows.Count > 0)
            {
                hidsid.Text = dt.Rows[0]["sid"].ToString();
                hidbh.Text = dt.Rows[0]["schbh"].ToString();

                txtschool.Text = dt.Rows[0]["schname"].ToString();
                txtperson.Text = dt.Rows[0]["person"].ToString();

                txttel.Text = dt.Rows[0]["stel"].ToString();
                txtfax.Text = dt.Rows[0]["sfax"].ToString();
                txtemail.Text = dt.Rows[0]["semail"].ToString();
                txtaddress.Text = dt.Rows[0]["saddress"].ToString();
                txtpost.Text = dt.Rows[0]["spost"].ToString();
                txtwebsite.Text = dt.Rows[0]["sweb"].ToString(); 
                txtfax.Text = dt.Rows[0]["sfax"].ToString();

                txtsx.Text = dt.Rows[0]["sxdate"].ToString();

                txttelm.Text = dt.Rows[0]["mtel"].ToString();
                txtqq.Text = dt.Rows[0]["qq"].ToString();
                txtmsn.Text = dt.Rows[0]["msn"].ToString();

                txtsex.Text = dt.Rows[0]["psex"].ToString();
                txtjob.Text = dt.Rows[0]["pjob"].ToString();
                txtsize.Text = dt.Rows[0]["psize"].ToString();
                string rdate = dt.Rows[0]["rdate"].ToString().Trim();
                if (rdate.Substring(0, 4) != "1900")
                {
                  DateTime   lastday = DateTime.Parse(rdate);
                  date1.Text = lastday.ToString("yyyy-M-d");
                }

                ddlxz.SelectedIndex = ddlxz.Items.IndexOf(ddlxz.Items.FindByValue(dt.Rows[0]["schxz"].ToString()));
                ddltype.SelectedIndex = ddltype.Items.IndexOf(ddltype.Items.FindByValue(dt.Rows[0]["schtype"].ToString()));

                FCKeditor1.Value = HttpUtility.HtmlDecode(dt.Rows[0]["memo"].ToString());
            
            }

        }

   


      
        protected void btnSubmit_Click(object sender, EventArgs e)
        {
            Model.SC.schools jb = new Model.SC.schools();
            jb.sid =int.Parse(hidsid.Text);
            jb.schbh =hidbh.Text; //岗位编号
            if (jb.schbh == "") return;


            jb.schname = txtschool.Text;

            jb.person = txtperson.Text;

            jb.stel = txttel.Text;
            jb.sfax = txtfax.Text;


            jb.semail = txtemail.Text;
            jb.saddress = txtaddress.Text;
            jb.spost = txtpost.Text;
            jb.sweb = txtwebsite.Text;
            jb.slevel = "";
            if (string.IsNullOrEmpty(date1.Text.Trim()))
                date1.Text = "1900-01-01";

            jb.rdate = DateTime.Parse(date1.Text.Trim());

            jb.type = ddltype.SelectedValue;
            jb.xz = ddlxz.SelectedValue;

            jb.mtel = txttelm.Text;
            jb.qq = txtqq.Text;
            jb.msn = txtmsn.Text;
            jb.pjob = txtjob.Text;
            jb.psex = txtsex.Text;
            jb.psize = txtsize.Text;

            jb.sales = us;
            jb.updtime = DateTime.Now;

            jb.memo = HttpUtility.HtmlEncode(FCKeditor1.Value);

            BLL.SC.schools sco = new BLL.SC.schools();
            sco.Update(jb);


            //更新业务员操作记录
            //BLL.Bllbase.update_rec(tab, um, " schbh='" + jb.schbh + "' ");
            //增加内容
            string sqltxt = "update  " + tab + " set sxdate='" + txtsx.Text + "' where schbh='" + jb.schbh + "'";
            DAL.DbHelperSQL.ExecuteNonQuery(sqltxt);

            Alert.Show("修改完成 ");
            PageContext.RegisterStartupScript(ActiveWindow.GetHidePostBackReference());
       
        }

       
    }
}